﻿using System;

using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Xml.Serialization;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;

using log4net;
using log4net.Config;
using System.Reflection;

namespace AutoRule
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Info("Server Start");
            
                CObserver.GetInstance().Init();
                CConfig.GetInstance().Init();
                CDB.GetInstance().Init(CConfig.GetInstance()._dbip, CConfig.GetInstance()._dbname, CConfig.GetInstance()._dbuser, CConfig.GetInstance()._dbpwd);
                CRegRuleManager.GetInstance().Parse();
                CTimerRuleManager.GetInstance().Parse();
                COffsetRules.GetInstance().Parse();
                CLimitRules.GetInstance().Parse();
                CRegMainWorker regworker = new CRegMainWorker();
                regworker.Start();
                CTimerTaskWorker timerworker = new CTimerTaskWorker();
                timerworker.Start();
                CExpWarOffsetWorker OffsetWorker = new CExpWarOffsetWorker();
                OffsetWorker.Start();
                CExpWarLimitWorker limitworker = new CExpWarLimitWorker();
                limitworker.Start();
                CHttpServer httpserver = new CHttpServer();
                httpserver.Run();



    
            }
            catch( Exception e){
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("未处理异常", e);
                Console.ReadKey();
            }
        }

        
        

        
        

        
        //public static bool insertlog(String sql)
        //{
        //    if (cns == null) {
        //        cns = new SqlConnection(connString);
        //        cns.Open();//打开一次
        //    }
        //    SqlCommand sqlcom = new SqlCommand(sql, cns);
        //    sqlcom.ExecuteNonQuery();
           
        //    //cns.Close();因为日志都需要调用到 所以不需要关闭

        //    return true;
        //}



        
    }
}
